#!/bin/bash

shopt -s extglob


base_version='current'

if [ $# -eq 0 ]
then
    cat <<-EOF
	Usage:
	  $0 <base-version> [<new-directory-name>]
	EOF
    exit 0
fi

if [ $# -ge 1 ]
then
    base_version=$1
fi

if [ $# -eq 2 ]
then
    new_dir_name=${2}
else
    new_dir_name=${USER}-$(echo ${base_version} | sed -e s/_/-/g)
fi

working_dir=$(pwd)
module_name=$(basename ${working_dir})

case ${working_dir} in
    /usr/oem-dev/*/*)
        oem_name=$(basename $(dirname ${working_dir}))
        module_name="${oem_name}-${module_name}"
    ;;
esac

cvs-co-version ${module_name} ${base_version} ${new_dir_name}

cd ${new_dir_name}/src

if echo "${base_version}" | egrep -s '^[0-9]+_[0-9]+_[0-9]+$'
then
    # frozen
    chmod -R ug+w .
fi

cvs-make-links
